<?php
/**
 * @license    GNU/GPL
 */

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

global $option;

/**
 * HTML View class for the CommunalMeals Component Admin
 *
 */

class CommunalMealsViewEditEventGroup extends JView
{
	function display($tpl = null)
	{
		global $option, $mainframe;
		
		$task = JRequest::getVar('task', NULL);
		$isNew = false;
		$eventGroup = NULL;
		if ($task == "add") {
			$isNew = true;
		}
		else {
			JError::raiseWarning("500", "No add or edit task in request");
			return;
		}

		// Prepare lists etc.
		$lists = array();
		$disabled = ($isNew)?'':'disabled="disabled"';

		// Year List: Dynamic 5 years from current year
		$yearList = array();
		$currentYear = date("Y");
		for ($i = 0; $i < 5; $i++) {
			$yearList[] = array('value' => $i+$currentYear, 'text' => $i+$currentYear);
		}
		if ($isNew) {
			$selectedYear = $currentYear;
		}
		else {
			//$selectedYear = 
		}
		$lists['year'] = JHTML::_('select.genericList', $yearList, 'year', 'class="inputbox" '.$disabled, 'value', 'text', $selectedYear );

		// Week List: Fixed 01-53
		$weekList = array();
		$currentWeek = date("W");
		for ($i = 1; $i <= 53; $i++) {
			$weekList[] = array('value' => str_pad($i, 2, "0", STR_PAD_LEFT), 'text' => $i);
		}
		if ($isNew) {
			$selectedWeek = $currentWeek;
		}
		else {
			//$selectedWeek = 
		}
		
		$lists['week'] = JHTML::_('select.genericList', $weekList, 'week', 'class="inputbox" '.$disabled, 'value', 'text', $selectedWeek );
		
		// Toolbar
		JToolBarHelper::title( JText::_( 'EVENT_GROUP_EDIT' ), 'generic.png' );
		JToolBarHelper::save('save'.(($isNew)?'_new':''));
		JToolBarHelper::cancel();
				
		// Pass data to template
		$this->assignRef( 'eventGroup', $eventGroup );
        $this->assignRef( 'lists', $lists );
		$this->assignRef( 'option', $option );
		
		parent::display($tpl);
	}
}